home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / enemy / BugD.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  15.7 KB  |  542 lines

  1. class classes.enemy.BugD
  2. {
  3.    var x;
  4.    var y;
  5.    var moveScript;
  6.    var id;
  7.    var clip;
  8.    var colorR;
  9.    var trans;
  10.    var colorTrans;
  11.    var f2;
  12.    var scc;
  13.    var axis;
  14.    var dir;
  15.    var switchDir;
  16.    var sfc;
  17.    var sfMax;
  18.    var xDest;
  19.    var yDest;
  20.    var oldDir;
  21.    var firing;
  22.    var fc;
  23.    var xMov = 0;
  24.    var yMov = 0;
  25.    var xMovT = 0;
  26.    var yMovT = 0;
  27.    var speedOrig = 9;
  28.    var speed = 9;
  29.    var xDestMet = false;
  30.    var yDestMet = false;
  31.    var c = 0;
  32.    var life = 6;
  33.    var nudging = false;
  34.    var nc = 0;
  35.    var xA = 0;
  36.    var yA = 0;
  37.    var power = 25;
  38.    var Name = "bugD";
  39.    function BugD(px, py, pmoveScript, pid)
  40.    {
  41.       this.x = px;
  42.       this.y = py;
  43.       this.moveScript = pmoveScript.slice();
  44.       this.id = pid;
  45.       _root.d = _root.d + 1;
  46.       this.clip = _root.attachMovie("bugA","bugD" + this.id + "Clip",_root.d + 50000);
  47.       this.clip._x = this.x;
  48.       this.clip._y = this.y;
  49.       this.speed *= _root.dif.speed;
  50.       this.speedOrig = this.speed;
  51.       this.life *= _root.dif.life;
  52.       this.colorR = -255;
  53.       this.trans = new flash.geom.Transform(this.clip);
  54.       this.colorTrans = new flash.geom.ColorTransform(0,0,0,1,this.colorR,this.colorR,this.colorR,0);
  55.       this.trans.colorTransform = this.colorTrans;
  56.       this.speedVar();
  57.       this.parseMoveScript();
  58.       _root.stats.created = _root.stats.created + 1;
  59.    }
  60.    function bombed(num)
  61.    {
  62.       this.f2 = "death";
  63.    }
  64.    function switchScope()
  65.    {
  66.       this.scc = 0;
  67.       this.getDirString();
  68.       this.f2 = "switchScoping";
  69.       this.c = 5;
  70.       this.speed /= 2;
  71.       this[this.axis + "MovT"] /= 2;
  72.       this.clip.body.flame.gotoAndStop("still");
  73.       _root.audio.playLevel2("bugDSwitch",_root.randRange(8,15));
  74.    }
  75.    function switchScoping()
  76.    {
  77.       this.c = this.c + 1;
  78.       if(this.c == 10)
  79.       {
  80.          this.scc = this.scc + 1;
  81.          this.c = 0;
  82.          if(this.dir == "U" || this.dir == "D")
  83.          {
  84.             _root.d = _root.d + 1;
  85.             _root.attachMovie("sight","sightClip",_root.d);
  86.             _root.sightClip.gotoAndStop("bugDSwitchFire");
  87.             _root.sightClip._x = this.x;
  88.             _root.sightClip._y = this.y;
  89.             if(_root.sightClip.hitTest(_root[_root.char].x,_root[_root.char].y,true))
  90.             {
  91.                this.switchFire("L");
  92.             }
  93.             else
  94.             {
  95.                _root.sightClip._rotation = 180;
  96.                if(_root.sightClip.hitTest(_root[_root.char].x,_root[_root.char].y,true))
  97.                {
  98.                   this.switchFire("R");
  99.                }
  100.             }
  101.             removeMovieClip(_root.sightClip);
  102.          }
  103.          else
  104.          {
  105.             _root.d = _root.d + 1;
  106.             _root.attachMovie("sight","sightClip",_root.d);
  107.             _root.sightClip.gotoAndStop("bugDSwitchFire");
  108.             _root.sightClip._x = this.x;
  109.             _root.sightClip._y = this.y;
  110.             _root.sightClip._rotation = 90;
  111.             if(_root.sightClip.hitTest(_root[_root.char].x,_root[_root.char].y,true))
  112.             {
  113.                this.switchFire("U");
  114.             }
  115.             else
  116.             {
  117.                _root.sightClip._rotation = -90;
  118.                if(_root.sightClip.hitTest(_root[_root.char].x,_root[_root.char].y,true))
  119.                {
  120.                   this.switchFire("D");
  121.                }
  122.             }
  123.             removeMovieClip(_root.sightClip);
  124.          }
  125.          if(this.scc > _root.randRange(9,12))
  126.          {
  127.             this.clip.body.gotoAndStop("main");
  128.             this.speed = this.speedOrig;
  129.             this[this.axis + "MovT"] *= 2;
  130.             this.clip.body.flame.gotoAndPlay("start");
  131.             this.f2 = "wander";
  132.          }
  133.       }
  134.    }
  135.    function switchFire(tmpDir)
  136.    {
  137.       this.clip.gotoAndStop("fly" + tmpDir);
  138.       this.switchDir = tmpDir;
  139.       this.c = 0;
  140.       this.sfc = 0;
  141.       this.f2 = "switchFiring";
  142.       this.sfMax = _root.randRange(1,2);
  143.    }
  144.    function switchFireBlast()
  145.    {
  146.       this.clip.body.gotoAndPlay("switchFire");
  147.       if(this.switchDir == "L")
  148.       {
  149.          var _loc3_ = this.x - 24;
  150.          var _loc4_ = this.dir != "U" ? this.y + 21 : this.y + 3;
  151.       }
  152.       else if(this.switchDir == "R")
  153.       {
  154.          _loc3_ = this.x + 9;
  155.          _loc4_ = this.dir != "U" ? this.y + 21 : this.y + 3;
  156.       }
  157.       else if(this.switchDir == "U")
  158.       {
  159.          _loc3_ = this.dir != "L" ? this.x + 21 : this.x + 3;
  160.          _loc4_ = this.y - 36;
  161.       }
  162.       else
  163.       {
  164.          _loc3_ = this.dir != "L" ? this.x + 21 : this.x + 3;
  165.          _loc4_ = this.y + 15;
  166.       }
  167.       _root.enemyShotID = _root.enemyShotID + 1;
  168.       _root["bugASwitchBlast" + _root.enemyShotID] = new classes.shots.BugASwitchBlast(_loc3_,_loc4_,this.switchDir,_root.enemyShotID,true);
  169.       _root.addEnemyShot("bugASwitchBlast" + _root.enemyShotID);
  170.       _root.audio.playLevel3("bugASwitchBlast" + (random(2) + 1),_root.randRange(15,25));
  171.    }
  172.    function switchFiring()
  173.    {
  174.       this.c = this.c + 1;
  175.       if(this.c == 10)
  176.       {
  177.          this.clip.body.gotoAndPlay("switch");
  178.       }
  179.       if(this.c == 17)
  180.       {
  181.          this.switchFireBlast();
  182.       }
  183.       if(this.c == 24)
  184.       {
  185.          this.switchFireBlast();
  186.          this.c = 18;
  187.          this.sfc = this.sfc + 1;
  188.          if(this.sfc == this.sfMax)
  189.          {
  190.             this.clip.body.gotoAndPlay("switchRev");
  191.             this.c = 33;
  192.          }
  193.       }
  194.       if(this.c == 45)
  195.       {
  196.          this.clip.gotoAndStop("fly" + this.dir);
  197.          this.clip.body.gotoAndStop("main");
  198.          this.speed = this.speedOrig;
  199.          this[this.axis + "MovT"] *= 2;
  200.          this.clip.body.flame.gotoAndPlay("start");
  201.       }
  202.    }
  203.    function nudge(pxA, pyA, pscale)
  204.    {
  205.       this.nc = 0;
  206.       this.nudging = true;
  207.       var _loc2_ = pscale / 100;
  208.       this.xA = pxA * _loc2_;
  209.       this.yA = pyA * _loc2_;
  210.    }
  211.    function speedVar()
  212.    {
  213.       if(random(3) == 1)
  214.       {
  215.          this.speed *= _root.randRange2(0.99999,1.00001);
  216.       }
  217.    }
  218.    function parseMoveScript()
  219.    {
  220.       this.dir = this.moveScript[0];
  221.       if(this.dir == "break")
  222.       {
  223.          delete this.moveScript;
  224.          if(random(2) == 1)
  225.          {
  226.             this.f2 = "wander";
  227.             this[this.axis + "MovT"] = 0;
  228.             this.axis = this.axis != "y" ? "y" : "x";
  229.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  230.             this.speedVar();
  231.             this.getDirString();
  232.          }
  233.          else
  234.          {
  235.             this.switchScope();
  236.          }
  237.       }
  238.       else
  239.       {
  240.          this[this.axis + "MovT"] = 0;
  241.          this.f2 = "gotoXYDest";
  242.          this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  243.          this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  244.          this.speedVar();
  245.          if(this.dir == "L" || this.dir == "U")
  246.          {
  247.             this[this.axis + "Dest"] = this[this.axis] - this.moveScript[1];
  248.          }
  249.          else
  250.          {
  251.             this[this.axis + "Dest"] = this[this.axis] + this.moveScript[1];
  252.          }
  253.          this.moveScript.splice(0,2);
  254.       }
  255.    }
  256.    function gotoXYDest()
  257.    {
  258.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  259.       {
  260.          if(this.axis == "x")
  261.          {
  262.             this.x = this.xDest;
  263.          }
  264.          else
  265.          {
  266.             this.y = this.yDest;
  267.          }
  268.          this.parseMoveScript();
  269.       }
  270.    }
  271.    function getDirString()
  272.    {
  273.       if(this.xMovT < -1)
  274.       {
  275.          this.dir = "L";
  276.       }
  277.       else if(this.xMovT > 1)
  278.       {
  279.          this.dir = "R";
  280.       }
  281.       else if(this.yMovT > 1)
  282.       {
  283.          this.dir = "D";
  284.       }
  285.       else if(this.yMovT < -1)
  286.       {
  287.          this.dir = "U";
  288.       }
  289.    }
  290.    function evade()
  291.    {
  292.       this[this.axis + "MovT"] = 0;
  293.       this.axis = this.axis != "x" ? "x" : "y";
  294.       this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  295.       this.getDirString();
  296.       this.f2 = "wander";
  297.    }
  298.    function attacking()
  299.    {
  300.       this.xMovT *= 1.03;
  301.       this.yMovT *= 1.03;
  302.    }
  303.    function death()
  304.    {
  305.       _root.stats.destroyed = _root.stats.destroyed + 1;
  306.       _root.stats.score += 2500;
  307.       _root.powerUpB(this.x,this.y,80,"rapidLaser",5);
  308.       _root.createExploD([this.x + this.clip._width / 2,this.y + this.clip._height / 2,_root.randRange(80,130),_root.randRange(75,100)]);
  309.       _root.audio.playLevel4("bugX" + (random(4) + 1),_root.randRange(7,17));
  310.       var _loc3_ = 0;
  311.       var _loc4_ = random(3);
  312.       while(_loc3_ < _loc4_)
  313.       {
  314.          _root.createShrapnel([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"bugA","",false,true]);
  315.          _loc3_ = _loc3_ + 1;
  316.       }
  317.       _root.removeChar("bugD" + this.id);
  318.       this.f2 = "";
  319.    }
  320.    function wander()
  321.    {
  322.       if(random(100) > 98 + _root.dif.wander)
  323.       {
  324.          this[this.axis + "MovT"] = 0;
  325.          this.axis = this.axis != "x" ? "x" : "y";
  326.          this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  327.          this.getDirString();
  328.       }
  329.       if(random(100) > 98 + _root.dif.wander)
  330.       {
  331.          this.switchScope();
  332.       }
  333.    }
  334.    function death2()
  335.    {
  336.       _root.removeChar("bugD" + this.id);
  337.       this.f2 = "";
  338.    }
  339.    function main()
  340.    {
  341.       this[this.f2]();
  342.       if(this.oldDir != this.dir)
  343.       {
  344.          this.clip.gotoAndStop("fly" + this.dir);
  345.       }
  346.       this.oldDir = this.dir;
  347.       if(random(300) >= 299 + _root.dif.wander)
  348.       {
  349.          _root.d = _root.d + 1;
  350.          _root.attachMovie("feeler","feelerClip",_root.d);
  351.          if(this.dir == "L")
  352.          {
  353.             var _loc9_ = [-310,0,300,50];
  354.          }
  355.          else if(this.dir == "R")
  356.          {
  357.             _loc9_ = [50,0,300,50];
  358.          }
  359.          else if(this.dir == "U")
  360.          {
  361.             _loc9_ = [0,-310,50,300];
  362.          }
  363.          else
  364.          {
  365.             _loc9_ = [0,50,300,50];
  366.          }
  367.          _root.feelerClip._x = this.x + _loc9_[0];
  368.          _root.feelerClip._y = this.y + _loc9_[1];
  369.          _root.feelerClip._width = _loc9_[2];
  370.          _root.feelerClip._height = _loc9_[3];
  371.          var _loc4_ = 0;
  372.          var _loc8_ = _root.chars.length;
  373.          var _loc7_ = false;
  374.          while(_loc4_ < _loc8_)
  375.          {
  376.             var _loc6_ = _root.chars[_loc4_] + "Clip";
  377.             if(_root.feelerClip.hitTest(_root[_loc6_]))
  378.             {
  379.                var _loc3_ = _root.chars[_loc4_];
  380.                if(_root[_loc3_].Name.substr(0,3) != "bro")
  381.                {
  382.                   _loc7_ = true;
  383.                }
  384.             }
  385.             _loc4_ = _loc4_ + 1;
  386.          }
  387.          removeMovieClip(_root.feelerClip);
  388.          if(!_loc7_)
  389.          {
  390.             _root.d = _root.d + 1;
  391.             _root.attachMovie("sight","sightClip",_root.d);
  392.             _root.sightClip._x = this.x;
  393.             _root.sightClip._y = this.y;
  394.             if(this.dir == "U")
  395.             {
  396.                _root.sightClip._rotation = 90;
  397.             }
  398.             else if(this.dir == "R")
  399.             {
  400.                _root.sightClip._rotation = 180;
  401.             }
  402.             else if(this.dir == "D")
  403.             {
  404.                _root.sightClip._rotation = -90;
  405.             }
  406.             if(_root.sightClip.hitTest(_root[_root.char].x,_root[_root.char].y,true))
  407.             {
  408.                this.clip.body.charger.gotoAndPlay("fire");
  409.                this.clip.body.eye1.gotoAndPlay("fire");
  410.                this.clip.body.eye2.gotoAndPlay("fire");
  411.                this.clip.body.eye3.gotoAndPlay("fire");
  412.                this.firing = true;
  413.                this.fc = 0;
  414.             }
  415.             removeMovieClip(_root.sightClip);
  416.          }
  417.       }
  418.       if(this.firing)
  419.       {
  420.          this.fc = this.fc + 1;
  421.          if(this.fc == 5)
  422.          {
  423.             if(this.dir == "L")
  424.             {
  425.                var _loc10_ = this.x - 24;
  426.                var _loc13_ = this.y + 12;
  427.                var _loc14_ = this.x - 24;
  428.                var _loc12_ = this.y + 6;
  429.             }
  430.             else if(this.dir == "R")
  431.             {
  432.                _loc10_ = this.x + 9;
  433.                _loc13_ = this.y + 12;
  434.                _loc14_ = this.x + 9;
  435.                _loc12_ = this.y + 6;
  436.             }
  437.             else if(this.dir == "U")
  438.             {
  439.                _loc10_ = this.x + 12;
  440.                _loc13_ = this.y - 24;
  441.                _loc14_ = this.x + 6;
  442.                _loc12_ = this.y - 24;
  443.             }
  444.             else
  445.             {
  446.                _loc10_ = this.x + 12;
  447.                _loc13_ = this.y + 3;
  448.                _loc14_ = this.x + 6;
  449.                _loc12_ = this.y + 3;
  450.             }
  451.             _root.enemyShotID = _root.enemyShotID + 1;
  452.             _root["bugAFireA" + _root.enemyShotID] = new classes.shots.BugAFireA(_loc10_,_loc13_,this.dir,_root.enemyShotID,true);
  453.             _root.addEnemyShot("bugAFireA" + _root.enemyShotID);
  454.             _root.enemyShotID = _root.enemyShotID + 1;
  455.             _root["bugAFireB" + _root.enemyShotID] = new classes.shots.BugAFireB(_loc14_,_loc12_,this.dir,_root.enemyShotID,true);
  456.             _root.addEnemyShot("bugAFireB" + _root.enemyShotID);
  457.             _root.audio.playLevel3("bugAFire",_root.randRange(15,25));
  458.          }
  459.       }
  460.       if(this.nudging)
  461.       {
  462.          this.xA *= 0.5;
  463.          this.yA *= 0.5;
  464.          this.nc = this.nc + 1;
  465.          var _loc11_ = 255 - this.nc * 17;
  466.          this.colorTrans.redOffset = _loc11_;
  467.          this.trans.colorTransform = this.colorTrans;
  468.          if(this.nc == 15)
  469.          {
  470.             this.xA = this.yA = 0;
  471.             this.nudging = false;
  472.             this.colorTrans.redOffset = this.colorR;
  473.             this.trans.colorTransform = this.colorTrans;
  474.          }
  475.       }
  476.       _loc4_ = 0;
  477.       _loc8_ = _root.broShots.length;
  478.       while(_loc4_ < _loc8_)
  479.       {
  480.          _loc6_ = _root.broShots[_loc4_] + "Clip";
  481.          if(this.clip.hitTest(_root[_loc6_]))
  482.          {
  483.             _loc3_ = _root.broShots[_loc4_];
  484.             var _loc5_ = this.life;
  485.             this.life -= _root[_loc3_].power;
  486.             if(this.life < 1)
  487.             {
  488.                this.f2 = "death";
  489.             }
  490.             else
  491.             {
  492.                this.nudge(_root[_loc3_].xMov,_root[_loc3_].yMov,5);
  493.                _root.audio.playLevel4("bugHit" + (random(4) + 1),_root.randRange(7,15));
  494.             }
  495.             _root[_root.char].fc = _root[_root.char].fireFreq - _root.rapidVar;
  496.             _root[_loc3_].exploX = this.x + this.clip._width / 2;
  497.             _root[_loc3_].exploY = this.y + this.clip._height / 2;
  498.             _root[_loc3_].hit(_loc5_);
  499.             break;
  500.          }
  501.          _loc4_ = _loc4_ + 1;
  502.       }
  503.       if(this.clip.hitTest(_root[_root.char + "Clip"]))
  504.       {
  505.          _root[_root.char].hit(this.xMov,this.yMov,100,this.power);
  506.          this.f2 = "death";
  507.       }
  508.       if(this.x > 1050 || this.x < -50 || this.y < -50 || this.y > 650)
  509.       {
  510.          this.f2 = "death2";
  511.       }
  512.       if(this.xMovT < this.xMov)
  513.       {
  514.          this.xMov -= 1;
  515.       }
  516.       else if(this.xMovT > this.xMov)
  517.       {
  518.          this.xMov += 1;
  519.       }
  520.       else
  521.       {
  522.          this.xMov = this.xMovT;
  523.       }
  524.       if(this.yMovT < this.yMov)
  525.       {
  526.          this.yMov -= 1;
  527.       }
  528.       else if(this.yMovT > this.yMov)
  529.       {
  530.          this.yMov += 1;
  531.       }
  532.       else
  533.       {
  534.          this.yMov = this.yMovT;
  535.       }
  536.       this.x += this.xMov + this.xA;
  537.       this.y += this.yMov + this.yA;
  538.       this.clip._x = this.x;
  539.       this.clip._y = this.y;
  540.    }
  541. }
  542.